package main

import (
	"bufio"
	"github.com/nsqio/go-nsq"
	"log"
	"os"
	"strings"
)

func main() {
	var nsqAddr = "127.0.0.1:4150"
	config := nsq.NewConfig()
	producer, err := nsq.NewProducer(nsqAddr, config)
	if err != nil {
		log.Fatalf("new producer err: %s\n", err)
	}
	reader := bufio.NewReader(os.Stdin)
	for {
		data, err := reader.ReadString('\n')
		if err != nil {
			log.Printf("read string err %s\n", err)
			continue
		}
		data = strings.TrimSpace(data)
		if strings.ToUpper(data) == "Q" {
			break
		}
		err = producer.Publish("test", []byte(data))
		if err != nil {
			log.Printf("publish err %s\n", err)
		}
	}
}
